home *** CD-ROM | disk | FTP | other *** search
/ 3D World 110 / 3DW_110.iso / mac / Menu / Scenes / home.dir / 00038_Script_Hypertext - General < prev    next >
Text File  |  2008-09-12  |  7KB  |  194 lines

  1. -- Hypertext - General
  2. -- script by chris walcott cwalcott@macromedia.com
  3. -- spiritual advice by glenn ruehle
  4. -- flight instruction by james newton
  5.  
  6. -- SCRIPT HISTORY:
  7. -- 10/27/98 1.0 - initial release.
  8. -- 10/30/98 1.0.1 - added https://, ftp:// schemes.  added relative 
  9. -- filepath support.  "lingo:" is now required to start the data 
  10. -- string for the "do" command.
  11. -- 11/2/98 1.0.2 - added error checking.
  12. -- 11/5/98 1.0.3 - updated description and tooltip.  Added custom thumbnail.
  13. -- 1/11/00       - added isOKToAtach and removed unneeded eror checking
  14.  
  15. -- NOTES ON USING THIS SCRIPT
  16. -- This behavior can be used for any text member that has hyperlinks.
  17.  
  18. -- If the data associated with he hyperlink starts with "http://", 
  19. -- "https://", "ftp://", or "mailto:" it will perform a gotoNetPage on 
  20. -- the data string.
  21.  
  22. -- Relative filepaths are supported. If the data associated with he 
  23. -- hyperlink starts with "./", "../", or "@" it will perform a 
  24. -- gotoNetPage on the data string.
  25. -- Please note that the "@" symbol works from anywhere and the unix 
  26. -- style path delimiters "./" and "../" only work from Shockwave.
  27.  
  28. -- Lingo commands can be execuited by starting the data string with
  29. -- "lingo:"  For example:
  30. --     lingo:beep
  31. -- would cause a beep to play when the hyperlink is clicked.
  32. -- If the lingo command requires  a quoted string, use single quotes. 
  33. -- For example, the following lingo command:
  34. --     go to movie "myMovie.dir"
  35. -- would be placed in the data field like this:
  36. --     lingo:go to movie 'myMovie.dir'
  37. -- 
  38. -- The Behavior Description Property dialog allows you to set 
  39. -- useHyperlinkStyles on or off.
  40.  
  41. property spriteNum
  42. property pHyperStyle
  43. property getPDLError
  44.  
  45. on getBehaviorDescription me
  46.   return \
  47.     "GENERAL PURPOSE HYPERLINK BEHAVIOR" & RETURN & RETURN & \
  48.     "This is a hyperlink behavior that operates on hyperlink data. " & \
  49.     "It will interpret the DATA string depending on what is at the beginning of the string." & RETURN & RETURN & \
  50.     "PARAMETERS:" & RETURN & \
  51.     "* Use hyperlink styles - Check if you want to use the built in hyperlink style." & RETURN & RETURN & \
  52.     "USEAGE:" & RETURN & \
  53.     "* URL schemes. " & \
  54.     "The following URL schemes are supported by this behavior:" & RETURN & \
  55.     "            http://   https://   mailto:   ftp://" & RETURN & \
  56.     "When the data string assigned to a hyperlink starts with one of these schemes, clicking it will perform a gotoNetPage on the URL" & RETURN & \
  57.     "* RELATIVE filepaths. " & \
  58.     "Relative file paths are supported. " & \
  59.     "You may start the hyperlink data string with the following:" & RETURN & \
  60.     "            ./   ../   @" & RETURN & \
  61.     "When the data string assigned to a hyperlink starts with one of these strings, clicking it will perform a gotoNetPage on the filepath." & RETURN & \
  62.     "NOTE: the \" & QUOTE & " @ \" & QUOTE & " symbol works in any environment. " & \
  63.     "The Unix style path delimiters \" & QUOTE & " ./ \" & QUOTE & " and \" & QUOTE & " ../ \" & QUOTE & " only work from Shockwave." & RETURN & \
  64.     "* LINGO. " & \
  65.     "Any string starting with \" & QUOTE & "lingo:\" & QUOTE & " will be treated as a Lingo command and will be executed with the Lingo \" & QUOTE & "do\" & QUOTE & " command. " & \
  66.     "If your Lingo command requires a quoted string, use single quotes. " & \
  67.     "The single quotes will be converted into double quotes before the command is execuited." & RETURN & RETURN & \
  68.     "For more information, open this script in the script editor and read the comments at the top."
  69. end getBehaviorDescription
  70.  
  71.  
  72. on getBehaviorTooltip me
  73.   return \
  74.     "Use this behavior on text members containing hyperlink data. " & \
  75.     "It will process URL's and Lingo commands."
  76. end getBehaviorTooltip
  77.  
  78.  
  79.  
  80. on beginSprite me
  81.   
  82.   theMember = sprite(spriteNum).member
  83.   
  84.   -- set useHyperlinkStyles on or off
  85.   if pHyperStyle = TRUE then
  86.     theMember.useHyperTextStyles = 1
  87.   else
  88.     theMember.useHyperTextStyles = 0
  89.   end if
  90.   
  91.   -- parse through each hyperlink and set it to #normal
  92.   repeat with i = 1 to theMember.hyperlinks.count
  93.     theLink = themember.hyperlinks[i]
  94.     theMember.char[theLink[1]].hyperlinkState = #normal
  95.   end repeat
  96.   
  97. end
  98.  
  99.  
  100. on hyperlinkClicked me, data, range  
  101.   
  102.   -- these should work from anywhere and will open up a browser.
  103.   if data starts "http://" then  
  104.     gotoNetPage (data)
  105.   else if data starts "https://" then
  106.     gotoNetPage (data)
  107.   else if data starts "ftp://" then
  108.     gotoNetPage (data)
  109.   else if data starts "@" then
  110.     gotoNetPage (data)
  111.   else if data starts "mailto:" then 
  112.     gotoNetPage (data)  -- go to Email page in browser
  113.     
  114.     -- these only work from shockwave
  115.   else if data starts "./" then
  116.     if the runMode = "plugin" then
  117.       gotoNetPage (data)  -- go to URL in browser
  118.     else
  119.       beep
  120.       alert "This relative filepath only works from Shockwave."
  121.     end if  
  122.   else if data starts "../" then
  123.     if the runMode = "plugin" then
  124.       gotoNetPage (data)  -- go to URL in browser
  125.     else
  126.       beep
  127.       alert "This relative filepath only works from Shockwave."
  128.     end if
  129.     
  130.     -- lingo command processing
  131.   else if data starts "lingo:" then
  132.     -- stript out the "lingo:"
  133.     theOffset = offset(":", data)
  134.     theCommand = data.char[(theOffset + 1)..data.char.count]
  135.     
  136.     -- reset the single quote to a double quote
  137.     repeat while offset("'", theCommand)
  138.       put QUOTE into theCommand.char[offset("'", theCommand)]
  139.     end repeat
  140.     
  141.     do theCommand  -- execute the command
  142.     
  143.   end if
  144.   
  145.   -- set the hyperlink to visited state
  146.   theMember = sprite(spriteNum).member
  147.   theMember.char[ range[1] ].hyperlinkState = #visited
  148.   
  149. end
  150.  
  151.  
  152.  
  153. on isOKToAttach (me, aSpriteType, aSpriteNum)
  154.   case aSpriteType of
  155.     #graphic:
  156.       return (sprite(aSpriteNum).member.type = #text)
  157.     #script:
  158.       return FALSE
  159.   end case
  160. end isOKToAttach 
  161.  
  162.  
  163.  
  164. on getPropertyDescriptionList me
  165.   
  166.   -- make sure we have a text sprite
  167.   if the currentspritenum <> 0 then
  168.     theMember = the member of sprite the currentspritenum
  169.     
  170.     -- make a list of all the hyperlinks in the text member
  171.     links=[]
  172.     links = theMember.hyperlinks
  173.     linkCount = links.count
  174.     
  175.     -- parse out any hyperlink data that contains a double quote
  176.     -- change the double quote to a single quote
  177.     repeat with i = 1 to linkCount
  178.       theLink = links[i]
  179.       theData = theMember.char[theLink[1]..theLink[2]].hyperlink
  180.       theData = theMember.char[theLink[1]].hyperlink
  181.       repeat while offset(QUOTE,theData)
  182.         put "'" into theData.char[offset(QUOTE,theData)]
  183.       end repeat
  184.     end repeat
  185.     
  186.     -- set up the property description dialog
  187.     p_list = [:]
  188.     addProp p_list, #pHyperStyle, [#format: #boolean, #default: TRUE, #comment: "Use hyperlink styles?"]
  189.     return p_list  
  190.   end if
  191.   
  192. end
  193.  
  194.